home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / MWCC03 / MAIN.ZIP / FILEDLG.PAS next >
Pascal/Delphi Source File  |  1993-08-18  |  7KB  |  272 lines

  1. {**********************************************************************}
  2. {*                                                                    *}
  3. {*          Microworks Custom Control Object Library                            *}
  4. {*                                                                    *}
  5. {*         Version 1.03                                                     *}
  6. {*                                                                    *}
  7. {*     Object Windows Library Extension for Borland Pascal v7.0       *}
  8. {*                                                                    *}
  9. {*     and Turbo Pascal for Windows v 1.5                             *}
  10. {*                                                                    *}
  11. {*         FileDlg.pas : Common File Dialog access unit                   *}
  12. {*                                                                    *}
  13. {*     Copyright 1992-93 Jeff Franks (Microworks) Sydney, Australia.  *}
  14. {*                                                                    *}
  15. {**********************************************************************}
  16.  
  17. {*** Introduction
  18.  
  19.     FileDlg.pas is a customizable unit that gives you access to the file open and
  20.     file save as objects in the MWCC.tpw(tpu) object unit. The dialogs are all set up
  21.     and ready to go. All you need to do is change the fields below (or add fields to
  22.     suit your application, include the unit in your uses clause and add the dialog
  23.     template from MCommDlg.res to your resource file.
  24.  
  25.     There are two different common dialog file objects, TSFXFileNameDlg and
  26.     TMWCCFileNameDlg. These dialogs match the other 'SFX' and 'MWCC' Window/Dialog
  27.     objects in the object unit.
  28.  
  29.     There are two examples at the end that show you how easy it is to add these dialogs to
  30.     your application.
  31.  
  32.  
  33. {*** TSFXFileDlg fields
  34.  
  35.     constructor Init(AParent: PWindowsObject; AName: PChar; IsOpen: Boolean);
  36.  
  37.         AName         := 'SFXFileDlg'
  38.  
  39.         IsOpen        := True (File Open dialog)
  40.  
  41.         IsOpen        := False (File Save As dialog);
  42.  
  43. {*** TMWCCFileDlg fields
  44.  
  45.     constructor Init(AParent: PWindowsObject; AName, ABmp: PChar; IsOpen: Boolean);
  46.  
  47.         AName         := 'MWCCFileDlg'
  48.  
  49.         ABmp          := 'BWCC' (BWCC style dialogs for the faithful)
  50.  
  51.                                     := 'MWCC' (My own snazzy Glazed dialogs)
  52.  
  53.                                     := nil (Conservative Light gray dialogs for the less adventurous)
  54.  
  55.         IsOpen        := True (File Open dialog)
  56.  
  57.         IsOpen        := False (File Save As dialog);
  58.  
  59. {*** Common dialog fields
  60.  
  61.         ADlg^.Execute := Returns - Filepath (Dir, Name and Ext)
  62.  
  63.                                                          - FileTitle (Name and Ext)
  64.  
  65.                                          if Ok button clicked. (See examples below)
  66.  
  67.         DefSpec       := Default file specifications
  68.  
  69.                                          eg. 'All Files (*.*)'#0'*.*'#0'Text Files (*.TXT)'#0'*.TXT'#0
  70.  
  71.         DefExt        := Default file extension to display when dialog first opens ( eg. '*.TXT')
  72.  
  73.         DefSpecPos    := Postion of default file specifcations (eg. above *.TXT would be '2')
  74.  
  75.         OpenFlags     := T(SFX/MWCC)FileNameDlg.OpenFlags are the default. They are ->
  76.  
  77.                                          if IsOpen is True -> ofn_PathMustExist or ofn_HideReadOnly
  78.  
  79.                                          if IsOpen is False -> ofn_PathMustExist or ofn_HideReadOnly or ofn_NoReadOnlyReturn;
  80.  
  81.                                          To change the default do something like this ->
  82.  
  83.                                          OpenFlags := TMWCCFileNameDlg.Open Flags and not ofn_HideReadOnly;
  84.  
  85.         CanClose      := You can change this if you want.
  86.  
  87.         DlgTitle      := The defaults are 'File Open' for file open dialogs and 'File Save As' for
  88.                                          file save as dialogs. You can overide these if you want.
  89.  
  90.                                          eg. DlgTitle := 'Program Browse';
  91.  
  92. {*** TSFXFileDlg Example
  93.  
  94.     procedure OpenFile (var Msg: TMessage);
  95.     var
  96.         Dir, Name, Ext: array[0..fsPathName] of Char;
  97.         ADlg : PSFXFileDlg;
  98.     begin
  99.         ADlg := (New(PSFXFileDlg, Init(@Self, 'SFXFileDlg', True)));
  100.         if ADlg <> nil then
  101.         begin
  102.             if ADlg^.Execute = idOk then
  103.             with ADlg^, OpenFileName do
  104.             begin
  105.                 FileSplit(FilePath, Dir, Name, Ext);
  106.                 ?
  107.                 ?   fill in this bit!
  108.                 ?
  109.                 ?
  110.             end;
  111.             ADlg^.free
  112.         end;
  113.     end;
  114.  
  115. {*** TMWCCFileDlg Example
  116.  
  117.     procedure OpenFile(var Msg: TMessage);
  118.     var
  119.         Dir, Name, Ext : array[0..fsPathName] of Char;
  120.         ADlg : PFileDlg;
  121.     begin
  122.         ADlg := (New(PFileDlg, Init(@Self, 'MWCCFileDlg', 'BWCC', True)));
  123.         if ADlg <> nil then
  124.         begin
  125.             if (ADlg^.Execute = idOk) then
  126.             with ADlg^, OpenFileName do
  127.             begin
  128.                 FileSplit(FilePath, Dir, Name, Ext);
  129.                 ?
  130.                 ?   fill in this bit!
  131.                 ?
  132.                 ?
  133.             end;
  134.             ADlg^.free
  135.         end;
  136.     end;
  137.  
  138. ***}
  139.  
  140. unit FileDlg;
  141.  
  142. {$R MCommDlg.Res}
  143. {$C Moveable DemandLoad Discardable}
  144.  
  145. interface
  146.  
  147. uses Wintypes, WinProcs, Strings, MObjects, MCommDlg,
  148.          {$IFDEF Ver15}
  149.              WObjects;
  150.          {$ELSE}
  151.              Objects, OWindows, ODialogs;
  152.          {$ENDIF}
  153.  
  154. type
  155.  
  156.     PSFXFileDlg = ^TSFXFileDlg;
  157.     TSFXFileDlg = object(TSFXFileNameDlg)
  158.         constructor Init(AParent: PWindowsObject; AName: PChar; IsOpen: Boolean);
  159.         destructor Done; virtual;
  160.     function DefSpec: PChar; virtual;
  161.     function DefExt: PChar; virtual;
  162.     function DefSpecPos: Byte; virtual;
  163.     function OpenFlags: Longint; virtual;
  164.     function CanClose: Boolean; virtual;
  165.     function DlgTitle: PChar; virtual;
  166.     private
  167.         Open : Boolean;
  168.     end;
  169.  
  170.     PMWCCFileDlg = ^TMWCCFileDlg;
  171.     TMWCCFileDlg = object(TMWCCFileNameDlg)
  172.         constructor Init(AParent: PWindowsObject; AName, ABmp: PChar; IsOpen: Boolean);
  173.         destructor Done; virtual;
  174.     function DefSpec: PChar; virtual;
  175.     function DefExt: PChar; virtual;
  176.     function DefSpecPos: Byte; virtual;
  177.     function OpenFlags: Longint; virtual;
  178.     function CanClose: Boolean; virtual;
  179.     function DlgTitle: PChar; virtual;
  180.     private
  181.         Open : Boolean;
  182.     end;
  183. implementation
  184.  
  185. {********** TSFXFileDlg **********}
  186.  
  187. constructor TSFXFileDlg.Init(AParent: PWindowsObject; AName: PChar; IsOpen: Boolean);
  188. begin
  189.     TSFXFileNameDlg.Init(AParent, AName, IsOpen);
  190.     Open := IsOpen;
  191. end;
  192.  
  193. destructor TSFXFileDlg.Done;
  194. begin
  195.     TSFXFileNameDlg.Done;
  196. end;
  197.  
  198. function TSFXFileDlg.DefSpec: PChar;
  199. begin
  200.     DefSpec := 'All Files (*.*)'#0'*.*'#0;
  201. end;
  202.  
  203. function TSFXFileDlg.DefExt: PChar;
  204. begin
  205.     DefExt := '*';
  206. end;
  207.  
  208. function TSFXFileDlg.DefSpecPos: Byte;
  209. begin
  210.     DefSpecPos := 1;
  211. end;
  212.  
  213. function TSFXFileDlg.OpenFlags: Longint;
  214. begin
  215.     OpenFlags := TSFXFileNameDlg.OpenFlags;
  216. end;
  217.  
  218. function TSFXFileDlg.CanClose: Boolean;
  219. begin
  220.     CanClose := TSFXFileNameDlg.CanClose;
  221. end;
  222.  
  223. function TSFXFileDlg.DlgTitle :PChar;
  224. begin
  225.     DlgTitle := TSFXFileNameDlg.DlgTitle;
  226. end;
  227.  
  228. {********** TMWCCFileDlg **********}
  229.  
  230. constructor TMWCCFileDlg.Init(AParent: PWindowsObject; AName, ABmp: PChar; IsOpen: Boolean);
  231. begin
  232.     TMWCCFileNameDlg.Init(AParent, AName, ABmp, IsOpen);
  233.     Open := IsOpen;
  234. end;
  235.  
  236. destructor TMWCCFileDlg.Done;
  237. begin
  238.     TMWCCFileNameDlg.Done;
  239. end;
  240.  
  241. function TMWCCFileDlg.DefSpec: PChar;
  242. begin
  243.     DefSpec := 'All Files (*.*)'#0'*.*'#0;
  244. end;
  245.  
  246. function TMWCCFileDlg.DefExt: PChar;
  247. begin
  248.     DefExt := '*';
  249. end;
  250.  
  251. function TMWCCFileDlg.DefSpecPos: Byte;
  252. begin
  253.     DefSpecPos := 1;
  254. end;
  255.  
  256. function TMWCCFileDlg.OpenFlags: Longint;
  257. begin
  258.     OpenFlags := TMWCCFileNameDlg.OpenFlags;
  259. end;
  260.  
  261. function TMWCCFileDlg.CanClose: Boolean;
  262. begin
  263.     CanClose := TMWCCFileNameDlg.CanClose;
  264. end;
  265.  
  266. function TMWCCFileDlg.DlgTitle :PChar;
  267. begin
  268.     DlgTitle := TMWCCFileNameDlg.DlgTitle;
  269. end;
  270.  
  271. end.
  272.